package cn.hl.sfzy.service.impl;

import cn.hl.sfzy.entity.*;
import cn.hl.sfzy.mapper.ConsultMapper;
import cn.hl.sfzy.mapper.ConsultReplyMapper;
import cn.hl.sfzy.mapper.UserMapper;
import cn.hl.sfzy.service.ConsultReplyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName ConsultReplyServiceImpl
 * @Description TODO
 * @Author LiuYao
 * @Date 2024年10月26日 10:56
 * @Version 1.0
 */
@Service
public class ConsultReplyServiceImpl implements ConsultReplyService {
    @Autowired
    private ConsultReplyMapper consultReplyMapper;
    @Autowired
    private ConsultMapper consultMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public int delete(Long id) {
        return consultReplyMapper.delete(id);
    }

    @Override
    public int add(ConsultReply consultReply) {
        return consultReplyMapper.insert(consultReply);
    }

    @Override
    public int update(ConsultReply consultReply) {
        return consultReplyMapper.update(consultReply);
    }

    @Override
    public PageInfo<ConsultReply> findByPage(int pageNum, int pageSize, ConsultReply consultReply) {
        PageHelper.startPage(pageNum,pageSize);
        List<ConsultReply> list= consultReplyMapper.select(consultReply);
        for(ConsultReply at : list){
            Consult consult = consultMapper.selectById(at.getConsult_id());
            User user=userMapper.selectById(at.getUser_id());
            at.setConsult(consult);
            at.setUser(user);
        }
        PageInfo<ConsultReply> pageInfo=new PageInfo(list);
        return pageInfo;
    }

    @Override
    public int deleteByUserId(Long id) {
        int i = consultReplyMapper.deleteByUserId(id);
        return i;
    }
}
